home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
inkey4c.zip
/
INKEY.DOC
< prev
next >
Wrap
Text File
|
1993-03-17
|
15KB
|
337 lines
╔═══════════════════════════════════════════════════════════════╗
║ INKEY () version 1.0 ║
║ ║
║ Copyright 1993 by John H. Traphofner, Esq. ║
║ all rights reserved ║
╚═══════════════════════════════════════════════════════════════╝
╔═══════════════════════════════════════════════════════════════╗
║ SIMPLE LICENCE AGREEMENT ║
╚═══════════════════════════════════════════════════════════════╝
You can use Inkey() for as long as you like. However, before you can sell
any program developed with inkey(), you must send a REGISTERED version of
that program to me at the address below. If you would like the source code
for inkey(), send $5.00 (U.S.) to:
John H. Traphofner
Route 1 Box 18 TT
Interlachen, Florida 32148
I will send you a 5 1/4 inch disk with the latest version of this utility
and the source code. I will also include any other shareware programs I
might be working on at the time. If you want assistance with the utility
or if you have any comments or suggestions, I can be reached at:
DR. SNED'S RBBS
904-325-6558
FIDO NET 1:3649/15
The BBS is a free access BBS and has 12 CDROMS on-line so please enjoy it.
Just leave a comment or message to me (Co-Sysop) or to the Sysop, letting
us know where you heard about DR. SNED'S RBBS.
╔═══════════════════════════════════════════════════════════════╗
║ Simple Distribution Agreement ║
╚═══════════════════════════════════════════════════════════════╝
Inkey() may be freely copied or distributed so long as all of the original
files remain intact and unmodified and so long as no charge is made for the
program itself and only a nominal charge (not to exceed $3.00) is made for
copying the program.
╔══════════════════════════════════════════════╗
║ FILES ON DISTRIBUTION DISK ║
╚══════════════════════════════════════════════╝
INKEY DOC 15219 03-17-93 This Document explaining usage/licence
INKEY H 7956 03-16-93 Include header file for inkey()
KEYDEMO C 9379 03-17-93 Source code for demo of inkey() functions
INKEY_T OBJ 1046 03-16-93 Tiny Model object file
INKEY_S OBJ 1046 03-16-93 Small Model object file
INKEY_M OBJ 1053 03-16-93 Medium Model object file
INKEY_C OBJ 1046 03-16-93 Compact Model object file
INKEY_L OBJ 1053 03-16-93 Large Model object file
INKEY_H OBJ 1080 03-16-93 Huge Model object file
KEYDEMO COM 7594 03-17-93 Compiled version of Keydemo.C
╔═════════════════════════════════════════════════╗
║ unsigned int inkey(unsigned int) ; ║
║ ║
║ Associated global variable: KEY_WAIT ║
╚═════════════════════════════════════════════════╝
╔═══════════════════════════════════════════════════════════════╗
║Usage: parameter equals zero ║
║Returns the key being pressed as either an ASCII code or an ║
║extended code, depending on the key pressed. ║
╚═══════════════════════════════════════════════════════════════╝
╔═══════════════════════════════════════════════════════════════╗
║Usage: parameter greater than zero but less than 512: ║
║Returns Pressed [1] or Unpressed [0] state of the key that is║
║specified by the code in the parameter. ║
╚═══════════════════════════════════════════════════════════════╝
╔═══════════════════════════════════════════════════════════════╗
║Usage: parameter equals 512: ║
║Returns True for the presence of an Extended 101 keyboard or ║
║ False if non-extended keyboard is present. ║
╚═══════════════════════════════════════════════════════════════╝
╔═══════════════════════════════════════════════════════════════╗
║Usage parameter > 512 ║
║Returns True or False for ON/OFF or Pressed/NotPressed State ║
║of the special keys and key states left Ctrl, Right Ctrl, Left ║
║Alt, Right Alt, Numlock, Scroll Lock, CapsLock left and right ║
║shift, Insert ON / OFF , CAPSLOCK ON / OFF and NUMLOCK ON / ║
║OFF. ║
╚═══════════════════════════════════════════════════════════════╝
INKEY is a utility for reading the keyboard in 'C' language programs.
With it, you can include all possible key board combinations into your
program. Checking for a Page Down key press is as easy as writing:
if( inkey(PGDN) )
If the Page Down Key is pressed, the function will evaluate to TRUE , if
not pressed, it evaluates to FALSE.
Not all keys are available on all keyboards. To check for the Extended 101
keyboard in your program, use the following:
if( inkey(STATUS) ) or if( inkey(READ_101_KEY) )
The function evaluates to TRUE if a 101 keyboard is present and to FALSE
for the non-extended older 84 key keyboards.
To read what key is being pressed, use the following:
keyin = inkey(READ_KEY);
keyin will then be equal to the key code being pressed or to zero if no key
is being pressed. If an 'A' is being pressed, inkey(READ_KEY) will return a
65 , the ASCII code for a capital 'A'. If the F1 key is being pressed,
inkey(READ_KEY) will return a code of 315 [ 59 EXTENDED ] The inkey.h file
contains #defines that you might find useful.
Checking for a function key such as F1 could be done this way:
unsigned int keyin;
keyin = inkey(READ_KEY);
if (keyin == F1) printf("You pressed the F1 key");
Or if you choose, it could be done this way:
if(inkey(F1)) printf("You pressed the F1 key");
Or, if you like obscure numbers to obfuscate your code:
if(inkey(315)) printf("You have pressed the 315 [F1] key");
The inkey() function is not an input function that waits forever for a
key to be pressed before moving on. In fact, inkey is so quick to move on,
that it would miss most keypresses if it were not for the use of the global
variable KEY_WAIT . This variable controls the number of times the inkey
routine will poll the keyboard for a character before deciding that no key
is available. KEY_WAIT defaults to 2048. Rather on the high side. You
will have to experiment in your application for the right number. Too low
and you might not read the keypress, too high and you program can bog down
polling the key board.
However, there are times when you would rather NOT move on until a key
is pressed. Rather than be limited the number of polls in an unsigned int,
you can wait forever by setting KEY_WAIT to 0.
Doing this will suspend the operation of the program until a key is
pressed. "Press any key to continue" Could be written as :
printf("Press any key to continue");
KEY_WAIT = 0;
inkey(READ_KEY);
There are several other keys and key 'STATES' or 'STATUS' that inkey
can check. On a non-extended keyboard, inkey can check for the following:
ALT_PRESSED CTRL_PRESSED LSHIFT_PRESSED RSHIFT_PRESSED
SHIFT_PRESSED [ either left or right ]
These keys can not be checked using the inkey(READ_KEY) call but must
instead be called by name such as inkey(ALT_PRESSED) or
inkey(SHIFT_PRESSED). The TRUE / FALSE [1/0] result is returned by these
calls.
The non-extended keyboard can also be checked with inkey for the
following keyboard STATES:
INS_ON CAPSLOCK_ON NUMLOCK_ON
if( inkey(NUMLOCK_ON) ) printf("Your NumLock is toggled ON");
On an extended 101 keyboard, the following are also available:
SYSREQ_PRESSED CAPSLOCK_PRESSED NUMLOCK_PRESSED SCROLL_PRESSED
R_ALT_PRESSED R_CTRL_PRESSED L_ALT_PRESSED L_CTRL_PRESSED
Another use for the special key handling ability of inkey() is those handy
three key combinations Such as CTRL-ALT-Q . Three key combinations are
great for applications because the chances of accidently pressing that
combination is slim compared to an 'E' for Exit or even the 'ESC' key. An
example of checking for three keys is found in the file KEYDEMO>C.
do
{ .....
.....
printf("Press Control-ALT-Q to quit");
}while ( ! (inkey(CTRL_PRESSED) && inkey(ALT_Q) ) );
The loop will keep executing so long as there is no Ctrl-Alt-Q pressed. ALT_F10·····
INKEY APPENDIX ALT_F11·····
OF DEFINE NAMES USED ALT_F12········
IN INKEY.H ALT_F1······
ALT_F2······
SPECIAL KEYS AND STATUS ALT_F3······
ALT_F4······
╔══════════════════════════════╗ ALT_F5······
║ ALT_PRESSED ║ ALT_F6······
║ CAPSLOCK_ON ║ ALT_F7······
║ CAPSLOCK_PRESSED ║ ALT_F8······
║ CTRL_PRESSED ║ ALT_F9······
║ INS_ON········ ║ ALT_G
║ L_ALT_PRESSED·· ║ ALT_HOME·······
║ L_CTRL_PRESSED·· ║ ALT_H·········
║ LSHIFT_PRESSED ║ ALT_I
║ NUMLOCK_ON····· ║ ALT_INS········
║ NUMLOCK_PRESSED· ║ ALT_J
║ R_ALT_PRESSED··· ║ ALT_K
║ R_CTRL_PRESSED·· ║ ALT_L
║ RSHIFT_PRESSED ║ ALT_LBRACKET··
║ SCROLL_PRESSED·· ║ ALT_LEFT·······
║ SHIFT_PRESSED· ║ ALT_M
║ SYSREQ_PRESSED·· ║ ALT_MINUS···
╚══════════════════════════════╝ ALT_N
ALT_NUM_ENTER··
ALT_NUM_MINUS·
ALT_NUM_PLUS··
EXTENDED AND NON STANDARD KEYS ALT_NUM_SLASH··
······· ALT_O
······· ALT_P
ALT_0······· ALT_PERIOD
ALT_1······· ALT_PGDN·······
ALT_2······· ALT_PGUP·······
ALT_3······· ALT_Q
ALT_4······· ALT_R
ALT_5······· ALT_RBRACKET
ALT_6······· ALT_RIGHT······
ALT_7 ALT_S
ALT_8 ALT_SEMICOLON·
ALT_9 ALT_SLASH
ALT_A ALT_TAB········
ALT_ACCENT ALT_T·
ALT_APOSTROPHE· ALT_UP·········
ALT_ASTERIK ALT_U·
ALT_B ALT_V
ALT_BACK· ALT_W
ALT_BREAK ALT_X
ALT_BSLASH ALT_Y·
ALT_C ALT_Z
ALT_COMMA BACKSPACE
ALT_D BREAK_KEY
ALT_DEL········ CAPSLOCK
ALT_DOWN······· CENTER
ALT_E CTRL_@
ALT_END ··· CTRL__
ALT_ENTER CTRL_A
ALT_EQUAL··· CTRL_B
ALT_ESC CTRL_BACKSLASH
ALT_F CTRL_C CTRL_CARAT F10
CTRL_D F11·········
CTRL_DEL······· F12·········
CTRL_DOWN······ F2
CTRL_E F3
CTRL_END···· F4
CTRL_F F5
CTRL_F1 F6
CTRL_F10···· F7
CTRL_F11···· F8
CTRL_F12···· F9
CTRL_F2 HOME
CTRL_F3 INS
CTRL_F4······· LEFT
CTRL_F5····· NUMLOCK
CTRL_F6····· PGDN
CTRL_F7····· PGUP
CTRL_F8····· RIGHT
CTRL_F9····· SCROLL_LOCK···
CTRL_G SHIFT_F1
CTRL_H SHIFT_F10
CTRL_HOME··· SHIFT_F11···
CTRL_I SHIFT_F12···
CTRL_INS······· SHIFT_F2
CTRL_J SHIFT_F3
CTRL_K SHIFT_F4
CTRL_L SHIFT_F5
CTRL_LBRACKET· SHIFT_F6
CTRL_LEFT··· SHIFT_F7
CTRL_M SHIFT_F8
CTRL_N SHIFT_F9·
CTRL_NUM_ASTERICK SHIFT_TAB
CTRL_NUM_MINUS· SPACEBAR
CTRL_NUM_PLUS·· TAB
CTRL_NUM_SLASH· UP
CTRL_O·
CTRL_P
CTRL_PGDN···
CTRL_PGUP···
CTRL_PRINT··
CTRL_Q
CTRL_R
CTRL_RBRACKET
CTRL_RIGHT··
CTRL_S
CTRL_T
CTRL_U
CTRL_UP········
CTRL_V
CTRL_W
CTRL_X
CTRL_Y
CTRL_Z
DEL
DELETE·· ···
DOWN
END
ENTER
ESC
F1